package com.wisezone.permission.web;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.exception.WzWebException;
import com.wisezone.common.utils.BeanUtils;
import com.wisezone.common.web.BaseFormController;
import com.wisezone.permission.bean.entity.WzDatadictionaryEntity;
import com.wisezone.permission.bean.form.WzDatadictionaryForm;
import com.wisezone.permission.bean.search.WzDatadictionarySearch;
import com.wisezone.permission.service.WzDatadictionaryService;

/**
 * 
 *数据字典; InnoDB free: 24576 kB
 * 
 * @author create by create date 2010-08-27 10:05:04 update date 2010-08-27
 *         10:05:04
 * 
 */
@WzWebAnnotation(moduleName = "dataDictionary")
public class WzDatadictionaryController
		extends
		BaseFormController<WzDatadictionaryEntity, WzDatadictionarySearch, WzDatadictionaryForm> {

	/**
	  *
	  *
	  *
	  */
	private WzDatadictionaryService wzDatadictionaryService;
	
	private List<WzDatadictionaryEntity> parentList; // 父类列表

	/**
	 * 返回清空条件列表
	 * 
	 * @return
	 * @throws WzWebException
	 */
	public String toList() throws WzWebException {

		searchEntity = new WzDatadictionarySearch();
		pagination = this.wzDatadictionaryService.listFormByPage(searchEntity);
		return LIST;
	}

	/**
	 * 获得列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws WzWebException {

		searchEntity = getSearchEntity();
		pagination = this.wzDatadictionaryService.listFormByPage(searchEntity);
		return LIST;
	}

	/**
	 * 进入新增
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterNew() throws WzWebException {

		if (id != null) {
			entity = this.wzDatadictionaryService.findById(id);
			entity.setId(null);
		}
		return NEW_EDIT;
	}

	/**
	 * 进入修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterEdit() throws WzWebException {

		entity = this.wzDatadictionaryService.findById(id);
		return NEW_EDIT;
	}

	/**
	 * 进入查看
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterView() throws WzWebException {

		form = this.wzDatadictionaryService.findFormById(id);
		return VIEW;
	}

	/**
	 * 保存
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws WzWebException {

		if (id != null) {
			return update();
		}
		entity = getEntity();
		this.wzDatadictionaryService.save(entity);
		return toList();
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String update() throws WzWebException {

		entity = getEntity();
		WzDatadictionaryEntity oldEntity = this.wzDatadictionaryService.findById(id);
		BeanUtils.copyBean(oldEntity, entity);
		this.wzDatadictionaryService.update(oldEntity);
		return toList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws WzWebException {

		Collection<Serializable> idList = getIdList();
		if (idList != null) {
			this.wzDatadictionaryService.deleteAll(idList);
		}
		return toList();
	}
	
	

	public List<WzDatadictionaryEntity> getParentList() {
		parentList = this.wzDatadictionaryService.getParentList();
		return parentList;
	}

	public void setWzDatadictionaryService(
			WzDatadictionaryService wzDatadictionaryService) {
		this.wzDatadictionaryService = wzDatadictionaryService;
	}

}